package com.aike.service;

import com.aike.dao.PersonMapper;
import com.aike.pojo.Meta;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class PersonServiceImpl implements PersonService{

    private  PersonMapper personMapper;

    public void setPersonMapper(PersonMapper personMapper) {
        this.personMapper = personMapper;
    }

    public String register(String id, String password, Integer type) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("state", personMapper.register(id, password, type));
        return jsonObject.toJSONString();
    }

    public String updateMessage(Integer id, String password, String name, String sex, String email, String address, Integer credit, String imageUrl) {
        JSONObject jsonObject = new JSONObject();
        int v = personMapper.updateMessage(id, password, name, sex, email, address, credit, imageUrl);
        if(v == 1)
        {
            jsonObject.put("data", "null");
            jsonObject.put("meta", new Meta(200, "更新成功"));
        }
        else
        {
            jsonObject.put("data", "null");
            jsonObject.put("meta", new Meta(400, "更新失败"));
        }
        return jsonObject.toJSONString();
    }

    public String addReport(Integer id, String text, String imageUrl) {
        JSONObject jsonObject = new JSONObject();
        int v = personMapper.addReport(id, text, imageUrl);
        if(v == 1)
        {
            jsonObject.put("data", "null");
            jsonObject.put("meta", new Meta(200, "举报成功"));
        }
        else
        {
            jsonObject.put("data", "null");
            jsonObject.put("meta", new Meta(400, "举报失败"));
        }
        return jsonObject.toJSONString();
    }

    public String clockIn(Integer personId) {
        JSONObject jsonObject = new JSONObject();
        int v = personMapper.clockIn(personId);
        if(v == 1)
        {
            jsonObject.put("data", "null");
            jsonObject.put("meta", new Meta(200, "打卡成功"));
        }
        else
        {
            jsonObject.put("data", "null");
            jsonObject.put("meta", new Meta(400, "打卡失败"));
        }
        return jsonObject.toJSONString();
    }
}
